package com.wjpeng.wms.web.controller;

import com.wjpeng.wms.domain.Orderbill;
import com.wjpeng.wms.query.OrderBillQueryObject;
import com.wjpeng.wms.query.QueryObject;
import com.wjpeng.wms.service.IOrderbillService;
import com.wjpeng.wms.service.ISupplierService;
import com.wjpeng.wms.util.JSONResult;
import com.wjpeng.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("orderbill")
public class OrderbillController {
    @Autowired
    private IOrderbillService orderbillService;

    @Autowired
    private ISupplierService supplierService;


    @RequestMapping("list")
    @RequiredPermission("部门列表")
    public String list(Model model, @ModelAttribute("qo") OrderBillQueryObject qo){
        model.addAttribute("result",orderbillService.result(qo));
        model.addAttribute("suppliers",supplierService.list());
        return "orderbill/list";
    }

    @RequestMapping("input")
    @RequiredPermission("部门编辑")
    public String input(Model model,Long id){
        if(id != null){
            model.addAttribute("entity",orderbillService.get(id));

        }
        model.addAttribute("suppliers",supplierService.list());
        return "orderbill/input";
    }

    @RequestMapping("view")
    @RequiredPermission("部门编辑")
    public String view(Model model,Long id){
        if(id != null){
            model.addAttribute("entity",orderbillService.get(id));

        }
        model.addAttribute("suppliers",supplierService.list());
        return "orderbill/view";
    }

    @RequestMapping("delete")
    @ResponseBody
    @RequiredPermission("部门删除")
    public Object delete(Long id){
        if(id != null){
            orderbillService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    @RequiredPermission("部门新增/更新")
    public Object saveOrUpdate(Orderbill orderbill) throws Exception{
        orderbillService.saveOrUpdate(orderbill);
        return new JSONResult();
    }

    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long id) throws Exception{
        orderbillService.audit(id);
        return new JSONResult();
    }


}
